# 1.导包
import time
from selenium import webdriver
from selenium.webdriver import ActionChains
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By

# 2.创建浏览器驱动对象
# Firefox浏览器:
# driver = webdriver.Firefox()
# Chrome浏览器:
path = r"D:\Programs\Python\Python313\chromedriver.exe"
ser = Service(executable_path = path)
driver = webdriver.Chrome(service = ser)
# 使用Edge浏览器,不需要安装驱动
# driver = webdriver.Edge ()
# 3.打开Web页面
driver.get("http://121.43.169.97:8848/pageA.html")
driver.maximize_window()
time.sleep(3)
action = ActionChains(driver)
action.move_to_element(driver.find_element(by=By.CSS_SELECTOR, value = "button"))
action.perform()
time.sleep(3)
action.context_click(driver.find_element(by=By.CSS_SELECTOR, value = "#userA"))
action.perform()
time.sleep(3)
driver.find_element(by=By.CSS_SELECTOR, value = "#userA").send_keys("admin")
action.perform()
time.sleep(3)
action.double_click(driver.find_element(by=By.CSS_SELECTOR, value = "#userA"))
action.perform()


# 4.暂停
time.sleep(5)
# 5.关闭浏览器驱动对象
driver.quit()